package com.wp.targetOffer;

/**
 * @author 王萍
 * @date 2018/3/20 0020
 */
public class 从1到n数字中1出现的次数 {
    public static void main(String[] args) {
        System.out.println(numberOf1Between1AndN_Solution(13));
    }

    public static int numberOf1Between1AndN_Solution(int n) {
        int count = 0;
        for (int i, j = 1; j <= n; j++) {
            i = j;
            while (i  != 0) {
                if (i % 10 == 1) {
                    count++;
                }
                i /= 10;
            }
        }
        return count;
    }
}
